home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 3 / ct-rom iiib.zip / ct-rom iiib / OS2 / SPEL / ROLLBALL / ROLLSRC.ZIP / ERROR.C < prev    next >
Text File  |  1992-07-14  |  11KB  |  174 lines

  1. /***********************************************************************\
  2.  *                               Error.c                               *
  3.  *                 Copyright (C) by Stangl Roman, 1992                 *
  4.  * This Code may be freely distributed, provided the Copyright isn't   *
  5.  * removed.                                                            *
  6.  *                                                                     *
  7.  * Requires: Error.c    The routing General_Error                      *
  8.  *           Error.h    The include-file that defines the macros       *
  9.  *                      GEN_ERR, DOS_ERR                               *
  10.  *                                                                     *
  11.  * Error is a general errorhandler for OS/2 2.0 PM programmer to easy  *
  12.  * program development. The routine General_Error displays:            *
  13.  *      ErrModule       The module containing the error                *
  14.  *      ErrLine         The sourcecode line, that contains the error   *
  15.  *      Error           The error returned by an OS/2 API              *
  16.  * The routine requires the following parameters passed:               *
  17.  *      HAB hab         The anchor block handle                        *
  18.  *      HWND hwndFrame  The windowhandle of the frame window           *
  19.  *      HWND hwndClient The windowhandle of the client window          *
  20.  *      PSZ ErrModule   The pointer to the name of the module __FILE__ *
  21.  *      LONG ErrLine    The pointer to the sourcecodeline __LINE__     *
  22.  *                                                                     *
  23.  * The routine Dos_Error displays:                                     *
  24.  *      ErrModule       The module containing the error                *
  25.  *      ErrLine         The sourcecode line, that contains the error   *
  26.  *      Error           The error returned by an OS/2 API              *
  27.  * The routine requires the following parameters passed:               *
  28.  *      ReturnCode      The returncode of an os/2 API                  *
  29.  *      HWND hwndFrame  The windowhandle of the frame window           *
  30.  *      HWND hwndClient The windowhandle of the client window          *
  31.  *      PSZ ErrModule   The pointer to the name of the module __FILE__ *
  32.  *      LONG ErrLine    The pointer to the sourcecodeline __LINE__     *
  33.  *                                                                     *
  34.  * The routine User_Error displays:                                    *
  35.  *      ErrModule       The module containing the error                *
  36.  *      ErrLine         The sourcecode line, that contains the error   *
  37.  *      Error           The error indicated by the user                *
  38.  * The routine requires the following parameters passed:               *
  39.  *      PSZ ErrorCode   The errorcode of the user                      *
  40.  *      HWND hwndFrame  The windowhandle of the frame window           *
  41.  *      HWND hwndClient The windowhandle of the client window          *
  42.  *      PSZ ErrModule   The pointer to the name of the module __FILE__ *
  43.  *      LONG ErrLine    The pointer to the sourcecodeline __LINE__     *
  44. \***********************************************************************/
  45.  
  46. #include        "error.h"               /* Include headerfile */
  47.  
  48. void General_Error(HAB hab,HWND hwndFrame,HWND hwndClient,PSZ ErrModule,LONG ErrLine)
  49. {
  50. static PERRINFO         pErrInfoBlk;    /* Pointer to ERRINFO structure that is filled
  51.                                            by WinGetErrorInfo */
  52. static PSZ              pszOffset;      /* Pointer to the current error message returned
  53.                                            by WinGetErrorInfo */
  54. static unsigned char    ErrBuffer[512]; /* The whole error message that is displayed to
  55.                                            the user via WinMessageBox */
  56.  
  57. sprintf(ErrBuffer,"Error found in Module: %s\nLinenumber in Sourcecode: %d\n"\
  58.     "Error reported by OS/2: ",ErrModule,ErrLine);
  59.                                         /* Get last error for the current thread. We loop
  60.                                            until no more error is found, although errors
  61.                                            arn't stacked (but things may change) */
  62. while((pErrInfoBlk = WinGetErrorInfo(hab)) != (PERRINFO)NULL)
  63.     {
  64.     DosBeep(1000,200);                  /* Signal to user via speaker */
  65.     DosBeep(300,200);
  66.     DosBeep(1000,200);
  67.                                         /* Find offset in array of message offsets */
  68.     pszOffset = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
  69.                                         /* Address error message in array of messages and 
  70.                                            append error message to source code linenumber */
  71.     strcat(ErrBuffer,(((PSZ)pErrInfoBlk) + *((PSHORT)pszOffset)));
  72.     if((INT)hwndFrame && (INT)hwndClient)
  73.     if((WinMessageBox(HWND_DESKTOP,     /* Parent window is DESKTOP */
  74.         hwndFrame,                      /* Owner window is our frame */
  75.         (PSZ)ErrBuffer,                 /* General_Error message */
  76.                                         /* Title bar message */
  77.         "General Error Message Information",
  78.         GEN_ERR_MSGBOXID,               /* Message identifier */
  79.                                         /* Buttons Abort, Retry, Ignore */
  80.         MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION | MB_DEFBUTTON3))==MBID_ABORT)
  81.             {                           /* If user selected Abort, then close application */
  82.             WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
  83.             }
  84.     WinFreeErrorInfo(pErrInfoBlk);      /* Free resource segment */
  85.     }
  86. }
  87.  
  88. void Dos_Error(ULONG Error,HWND hwndFrame,HWND hwndClient,PSZ ErrModule,LONG ErrLine)
  89. {
  90. static unsigned char    MsgBuffer[512]; /* The whole error message that is displayed to
  91.                                            the user via WinMessageBox */
  92. static ULONG            Class;          /* Error class */
  93. static ULONG            Action;         /* Error action */
  94. static ULONG            Locus;          /* Error location */
  95.  
  96. static unsigned char    *Err_Class[]={"Out of ressource",
  97.                                       "Temporary situation",
  98.                                       "Authorization failed",
  99.                                       "Internal error",
  100.                                       "Device hardware failure",
  101.                                       "System failure",
  102.                                       "Probable application failure",
  103.                                       "Item not located",
  104.                                       "Bad format for call/data",
  105.                                       "Resource or data locked",
  106.                                       "Incorrect media, CRC check",
  107.                                       "Action already taken or done",
  108.                                       "Unclassified",
  109.                                       "Cannot perform requested action",
  110.                                       "Timeout",
  111.                                       "Error in file \"Error.c\""};
  112. static unsigned char    *Err_Action[]={"Retry immediately",
  113.                                        "Delay and retry",
  114.                                        "Bad user input - get new values",
  115.                                        "Terminate in an orderly manner",
  116.                                        "Terminate immediately",
  117.                                        "Ignore error",
  118.                                        "Retry after user intervention",
  119.                                        "Error in file \"Error.c\""};
  120. static unsigned char    *Err_Locus[]={"Unknown",
  121.                                       "Random access device such as a disk",
  122.                                       "Network",
  123.                                       "Serial device",
  124.                                       "Memory",
  125.                                       "Error in file \"Error.c\""};
  126.  
  127. if(Error!=0)
  128. {
  129.     DosBeep(1000,200);                  /* Signal to user via speaker */
  130.     DosBeep(300,200);
  131.     DosBeep(1000,200);
  132.     DosErrClass(Error,&Class,&Action,&Locus);
  133.     sprintf(MsgBuffer,"Error found in Module: %s\nLinenumber in Sourcecode: %d\n"\
  134.         "Error reported by OS/2: %d\nClass: %s\nAction: %s\n"\
  135.         "Location: %s\n",ErrModule,ErrLine,Error,Err_Class[Class-1],\
  136.         Err_Action[Action-1],Err_Locus[Locus-1]);
  137.     if((INT)hwndFrame && (INT)hwndClient)
  138.     if((WinMessageBox(HWND_DESKTOP,     /* Parent window is DESKTOP */
  139.         hwndFrame,                      /* Owner window is our frame */
  140.         (PSZ)MsgBuffer,                 /* DOS API error message */
  141.                                         /* Title bar message */
  142.         "OS/2 DosApi Error Message Information",
  143.         GEN_ERR_MSGBOXID,               /* Message identifier */
  144.                                         /* Buttons Abort, Retry, Ignore */
  145.         MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION | MB_DEFBUTTON3))==MBID_ABORT)
  146.             {                           /* If user selected Abort, then close application */
  147.             WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
  148.             }
  149. }
  150. }
  151.  
  152. void User_Error(PSZ Error,HWND hwndFrame,HWND hwndClient,PSZ ErrModule,LONG ErrLine)
  153. {
  154. static unsigned char    MsgBuffer[512]; /* The whole error message that is displayed to
  155.                                            the user via WinMessageBox */
  156.  
  157. DosBeep(1000,200);                      /* Signal to user via speaker */
  158. DosBeep(300,200);
  159. DosBeep(1000,200);
  160. sprintf(MsgBuffer,"Error found in Module: %s\nLinenumber in Sourcecode: %d\n"\
  161.     "%s\n",ErrModule,ErrLine,Error);
  162. if((INT)hwndFrame && (INT)hwndClient)
  163. if((WinMessageBox(HWND_DESKTOP,         /* Parent window is DESKTOP */
  164.     hwndFrame,                          /* Owner window is our frame */
  165.     (PSZ)MsgBuffer,                     /* User indicated error message */
  166.                                         /* Title bar message */
  167.     "User indicated Error Message Information",
  168.     GEN_ERR_MSGBOXID,                   /* Message identifier */
  169.                                         /* Buttons Abort, Retry, Ignore */
  170.     MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION | MB_DEFBUTTON3))==MBID_ABORT)
  171.                                         /* If user selected Abort, then close application */
  172.     WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
  173. }
  174.